﻿using Serilog;
using Serilog.Core;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using System;
using System.Text;

namespace SUNRPA.BROWSER.BRIDGE.util {
    public class LogUtil {
        public string context;
        public LogUtil(Type t){
            context = t.ToString() + "==";
        }
        public static Logger logger = new LoggerConfiguration().ReadFrom.AppSettings()
            .WriteTo.File(DefaultContents.LOG_BASE_PATH + "BridgeLog-.txt", 
                outputTemplate:"[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
                rollingInterval:RollingInterval.Day, retainedFileCountLimit : 20,
                encoding:Encoding.UTF8)
            .CreateLogger();
        
        public void Debug(string message, params object[] placeHolders) { 
            logger.Debug(context + message, placeHolders);
        }

        public void Info(string message, params object[] placeHolders) { 
            logger.Information(context + message, placeHolders);
        }

        public void Error(string message, Exception e, params object[] placeHolders) { 
            logger.Error(e, context + message, placeHolders);
        }

        public static void CloseLogger() { 
            logger.Dispose();
        }
    }
}
